package com.qg.controller;

import com.qg.utils.ActieMQaUtil;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.jms.JMSException;

@Controller
public class TestActivaMQController {

    @Resource
    ActieMQaUtil actieMQaUtil;

    /**
     * 发送消息
     * @return
     */
    @RequestMapping("/sendMassage")
    @ResponseBody
    public String sendMassage(){
        //传入标识和消息
        actieMQaUtil.sendQueueMesage("qg-test","I am TestActiveMQ!");
        return "succeed";
    }

    /**
     * 监听并接受消息
     * 如参数是是object会传入ActiveMQTextMessage对象
     * 则是String会自动传入ActiveMQTextMessage的getText()方法传入消息
     * @param massage
     */
    @JmsListener(destination = "qg-test")
    public void getMassage(String massage) throws JMSException {
        System.out.println(massage);
    }


}
